import request from "@/utlis/request";

//  request   导入就相当于导入了axios

export const loginApi = data => {
  return request.post("/v1_0/authorizations", data);
};

//  获取验证码
export const codeApi = mobile => {
  return request(`/v1_0/sms/codes/${mobile}`);
};

//  回去用户自己的信息   /v1_0/user
export const userApi = mobile => {
  return request(`/v1_0/user`);
};

//  获取自己的用户频道

export const channelsApi = mobile => {
  return request(`/v1_0/user/channels`);
};

//  频道新闻推荐_V1.1
export const channelsArticlesApi = obj => {
  return request(`/v1_1/articles`,{
    params:{
      channel_id:obj.channel_id,
      timestamp:obj.timestamp,
      with_top:obj.with_top
    }
  });
};
//  channelsArticlesApi({channel_id:1,timestamp:new  Date(),with_top:1})

//  获取所有的频道
export const channelsAllApi = () => {
  return request(`/v1_0/channels`);
};


/**
 * 删除用户指定频道
 */
export const deleteUserChannelApi = channelId => {
  return request({
    method: 'DELETE',
    url: `/v1_0/user/channels/${channelId}`
  })
}


//  搜索建议

// export const getSearchSuggestions = q => {
//   return request({
//     method: 'GET',
//     url: '/app/v1_0/suggestion',
//     params: {
//       q
//     }
//   })
// }


// export const getSearchSuggestionsApi = q => {
//   return request('/app/v1_0/suggestion?q='+q)
//   //return request(`/app/v1_0/suggestion?q=${q}`)
// }

export const getSearchSuggestionsApi = q => {
  return request('/v1_0/suggestion',{
    params: {
      q
    }
  })
}
//  搜索结果
// export const getSearchResult = params => {
//   return request({
//     method: 'GET',
//     url: '/v1_0/search',
//     params
//   })
// }

export const getSearchResultApi = params => {
  return request('/v1_0/search',{
    params
  })
}

/**
 * 获取文章
 */
export const getArticleByIdApi = articleId => {
  return request({
    method: 'GET',
    url: `/v1_0/articles/${articleId}`
  })
}


/**
 * 收藏文章
 */
export const addCollectApi = target => {
  return request({
    method: 'POST',
    url: '/v1_0/article/collections',
    data: {
      target
    }
  })
}

/**
 * 取消收藏文章
 */
export const deleteCollectApi = target => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/collections/${target}`
  })
}

/**
 * 点赞文章
 */
export const addLikeApi = target => {
  return request({
    method: 'POST',
    url: 'v1_0/article/likings',
    data: {
      target
    }
  })
}

/**
 * 取消点赞文章
 */
export const deleteLikeApi = target => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/likings/${target}`
  })
}


/**
 * 获取文章评论列表
 */
// export const getCommentsApi = params => {
//   return request({
//     method: 'GET',
//     url: '/v1_0/comments',
//     // GET 参数使用 params 进行传递
//     // 我们写的时候是对象，但是最终发给后端的数据是？
//     // axios 会把 params 对象转为 key=value?key=value 的格式放到 url 中发送
//     params
//   })
// }


export const getCommentsApi = params => {
  return request('/v1_0/comments',{params})
}

/**
 * 发布文章评论或评论回复
 */
export const addCommentApi = data => {
  return request({
    method: 'POST',
    url: '/v1_0/comments',
    data
  })
}


/**
 * 评论点赞
 */
export const addCommentLikeApi = target => {
  return request({
    method: 'POST',
    url: '/v1_0/comment/likings',
    data: {
      target
    }
  })
}

/**
 * 取消评论点赞
 */
export const deleteCommentLikeApi = target => {
  return request({
    method: 'DELETE',
    url: `/v1_0/comment/likings/${target}`
  })
}

/**
 * 更新用户照片资料
 */
export const updateUserPhotoApi = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data
  })
}

/**
 * 获取当前登录用户的个人资料
 */
export const getUserProfileApi = target => {
  return request({
    method: 'GET',
    url: '/v1_0/user/profile'
  })
}

/**
 * 更新用户资料
 */
export const updateUserProfileApi = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/profile',
    data
  })
}



